<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="设备SN号">
              <a-input placeholder="请输入设备SN号" v-model="queryParam.deviceSn"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() =>{ queryParam = {}}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator">
      <!--  <a-button @click="(e) => this.goToUpload()" style="margin-bottom: 8px">
         导入
       </a-button> -->

      <a-button @click="(e) => this.goToAdd()" style="margin-bottom: 8px;margin-left: 6px;" type="primary">
        新增
      </a-button>
    </div>
    <v-table
      :table-column="columns"
      :data="loadData"
      :rowKey="record => record.id"
      bordered
      ref="table"
    >
      <template v-slot:action='{ text, row }'>
        <div class="actionColumn">
          <span>
            <a-divider type='vertical'/>
            <a href='javascript:' @click='show(row)'>查看</a>
          </span>
          <span>
            <a-divider type='vertical'/>
            <a href='javascript:' @click='update(row)'>编辑</a>
          </span>
          <span>
            <a-divider type='vertical'/>
            <a-popconfirm title='是否删除' @confirm='deleteItem(row)' okText='是' cancelText='否'>
              <a-icon slot='icon' type='question-circle-o' style='color: red'/>
              <a href='javascript:' style='color: red'>删除</a>
            </a-popconfirm>
          </span>
        </div>
      </template>
    </v-table>
    <!--    <Wfudevice-upload-->
    <!--      @ok="queryPage"-->
    <!--      ref="WfudeviceUpload">-->
    <!--    </Wfudevice-upload>-->
    <Wfudevice-add-or-update
      @ok="queryPage"
      ref="WfudeviceAddOrUpdate">
    </Wfudevice-add-or-update>
  </a-card>

</template>

<script>
import {TableMixin} from '@/mixins/TableMixin'
import {fetchList, getObj, addObj, putObj, delObj} from '@api/device/device'
// import WfudeviceUpload from './WfudeviceUpload'
import WfudeviceAddOrUpdate from './WfudeviceAddOrUpdate'

export default {
  components: {
    // WfudeviceUpload,
    WfudeviceAddOrUpdate
  },
  mixins: [TableMixin],
  name: 'Wfudevice',
  data() {
    return {
      columns: [
        {
          title: '设备SN',
          field: 'deviceSn'
        },
        {
          title: '设备地点',
          field: 'deviceSpot'
        },
        {
          title: '设备组',
          field: 'deviceGroup'
        },
        {
          title: '备注',
          field: 'remarks'
        },
        {
          title: '操作',
          width: '200px',
          field: 'action',
          slot: true
        }
      ],
      queryParam: {
        name: ''
      },
      statusList: [
        {
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '2'
        }
      ],
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    // goToUpload () {
    //   this.$refs.WfudeviceUpload.show()
    // },
    goToAdd() {
      this.$refs.WfudeviceAddOrUpdate.edit(null, 'add')
    },
    handleChange(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        if (info.file.response.code === 0) {
          this.$message.success('导入成功！')
          this.init()
        } else if (info.file.response.code === 1) {
          this.$message.error(info.file.response.msg)
        }
        this.queryPage()
      } else if (info.file.status === 'error') {
        this.$message.error('导入失败，请重试！')
      }
    },
    show(record) {
      this.$refs.WfudeviceAddOrUpdate.edit(record.id, 'show')
    },
    update(record) {
      this.$refs.WfudeviceAddOrUpdate.edit(record.id, 'edit')
    },
    deleteItem(record) {
      delObj(record.id).then(res => {
        if (res.code === 0) {
          this.$message.info('删除成功')
          this.queryPage()
        } else {
          this.$message.warn(res.massage)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
